﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StyleMVVM.Notification.Tile
{
	internal class BaseTileUpdate : ITileUpdate
	{
		protected string templateName;
		protected string[] imageList;
		protected string[] textList;

		internal BaseTileUpdate(string templateName, int imageCount, int textCount)
		{
			this.templateName = templateName;

			imageList = new string[imageCount];
			textList = new string[textCount];

			Branding = NotificationBranding.Logo;
		}

		public bool AddImageQuery { get; set; }

		public string Lang { get; set; }

		public string BaseUri { get; set; }

		public string FallBack { get; set; }

		public NotificationBranding Branding { get; set; }

		public virtual string GenerateXML()
		{
			StringBuilder updateString = new StringBuilder();

			updateString.AppendFormat("<binding template=\"{0}\" ", templateName);

			if (AddImageQuery)
			{
				updateString.AppendFormat(" addImageQuery=\"true\" ");
			}

			if (!string.IsNullOrEmpty(Lang))
			{
				updateString.AppendFormat(" lang=\"{0}\" ", Lang);
			}

			if (!string.IsNullOrEmpty(BaseUri))
			{
				updateString.AppendFormat(" baseUri=\"{0}\" ", BaseUri);
			}

			if (!string.IsNullOrEmpty(FallBack))
			{
				updateString.AppendFormat(" fallback=\"{0}\" ", FallBack);
			}

			if (Branding != NotificationBranding.Logo)
			{
				updateString.AppendFormat(" branding=\"{0}\" ", Branding.ToString().ToLower());
			}

			updateString.AppendFormat(">");

			for (int i = 0; i < imageList.Length; i++)
			{
				updateString.AppendFormat("<image id=\"{0}\" src=\"{1}\" />", i + 1, imageList[i]);
			}

			for (int i = 0; i < textList.Length; i++)
			{
				updateString.AppendFormat("<text id=\"{0}\">{1}</text>", i + 1, textList[i]);
			}

			updateString.AppendFormat("</binding>");

			return updateString.ToString();
		}
	}
}